<template>
	<view class="content">
		<view class="box" v-for="item in auditList">
			<view class="box-con">
				<view class="box-con-left">店名:</view>
				<view class="box-con-right">
					{{ item.exJson.storeName }}
				</view>
			</view>
			<view class="box-con">
				<view class="box-con-left">店铺地址:</view>
				<view class="box-con-right">
					{{ item.exJson.province }}{{ item.exJson.city }}{{ item.exJson.district }}{{ item.exJson.address }}
				</view>
			</view>
			<view class="box-con">
				<view class="box-con-left">用户姓名:</view>
				<view class="box-con-right">
					{{ item.exJson.name }}
				</view>
			</view>
			<view class="box-con">
				<view class="box-con-left">电话:</view>
				<view class="box-con-right">
					{{ item.exJson.mobile }}
				</view>
			</view>
			<view class="box-con">
				<view class="box-con-left">状态:</view>
				<view class="" style="display: flex; flex: 1; align-items: center; justify-content: space-between">
					<view class="">
						<view class="box-con-right" v-if="item.isAudit == 1" style="color: #f1a532">审核中</view>
						<view class="box-con-right" v-else-if="item.isAudit == 2" style="color: #5ac725">审核通过</view>
						<view class="box-con-right" v-else-if="item.isAudit == 3" style="color: #f56c6c">
							审核不通过
						</view>
					</view>
					<view class="">
						<u-button
							type="primary"
							size="small"
							:plain="true"
							text="审核"
							v-if="item.isAudit == 1"
							@click="shenhe(item)"
						></u-button>
						<u-button
							type="primary"
							size="small"
							:plain="true"
							text="重新审核"
							v-else
							@click="shenhe(item)"
						></u-button>
					</view>
				</view>
			</view>
			<view class="box-con">
				<view class="box-con-left">申请时间:</view>
				<view class="box-con-right">
					{{ item.createTime }}
				</view>
			</view>
		</view>

		<u-modal :show="show" title="审核店铺" @close="show=false" :closeOnClickOverlay="true" :showCancelButton="true" @confirm="confirm" @cancel="cancel" confirmText="同意" cancelText="拒绝">
			<view class="model" style="width: 100%">
				<view class="model-con">
					<view class="model-con-left">优惠折扣:</view>
					<view class="model-con-right">
						<u--input
							placeholder="折扣值0 ~ 1"
							border="surround"
							v-model="form.exJson.discountRate"
						></u--input>
					</view>
				</view>
				<view class="model-con">
					<view class="model-con-left">专属销售:</view>
					<view class="model-con-right">
						<u--input
							placeholder="输入销售人员姓名"
							border="surround"
							v-model="form.exJson.salesmanName"
						></u--input>
					</view>
				</view>
				<view class="model-con">
					<view class="model-con-left">销售电话:</view>
					<view class="model-con-right">
						<u--input
							placeholder="输入销售人员电话"
							border="surround"
							v-model="form.exJson.salesmanPhone"
						></u--input>
					</view>
				</view>
				<view class="model-con">
					<view class="model-con-left">店铺图片:</view>
					<view class="model-con-right">
						<view class="" style="display: flex; align-items: center">
							<view class="" v-for="(item, index) in form.exJson.storeImg">
								<view class="" style="display: flex; flex-wrap: wrap">
									<image
										style="width: 100rpx; height: 100rpx; margin-bottom: 20rpx; margin-right: 10rpx"
										:src="item"
										@click="viewImage(form.exJson.storeImg, index)"
									></image>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="model-con">
					<view class="model-con-left">营业执照:</view>
					<view class="model-con-right">
						<view class="" style="display: flex; align-items: center">
							<view class="" v-for="(item, index) in form.exJson.licenseImg">
								<view class="" style="display: flex; flex-wrap: wrap">
									<image
										style="width: 100rpx; height: 100rpx; margin-bottom: 20rpx; margin-right: 10rpx"
										:src="item"
										@click="viewImage(form.exJson.licenseImg, index)"
									></image>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</u-modal>

		<view class="" style="margin-top: 200rpx" v-if="auditList.length == 0">
			<u-empty mode="data"></u-empty>
		</view>
	</view>
</template>

<script>
import { searchPlugsAuditList, updateAudit, plugsAudit } from '@/utils/api.js';
export default {
	data() {
		return {
			plugsId: '',
			auditList: [],
			show: false,
			form: {},
			rules: {},
			search: {
				page: 1,
				size: 10,
				total: 0
			}
		};
	},
	onLoad(option) {
		uni.setNavigationBarTitle({
			title: option.title
		});
		this.plugsId = option.plugsId;
	},
	onShow() {
		this.getauditList();
	},
	onReachBottom() {
		if (this.auditList.length < this.search.total) {
			this.search.page++;
			this.getauditList();
		}
	},
	methods: {
		getauditList() {
			let data = {
				page: this.search.page,
				size: this.search.size,
				adminId: uni.getStorageSync('userInfo').id,
				userServiceToken: uni.getStorageSync('userInfo').userServiceToken
			};
			searchPlugsAuditList(data).then((res) => {
				if (res.code == 200) {
					if (this.search.page == 1) {
						this.auditList = [];
					}
					res.body.list.forEach((item) => {
						item.exJson = JSON.parse(item.exJson);
					});
					let arr = [];
					arr = this.auditList.concat(res.body.list);
					this.auditList = arr;

					this.search.total = res.body.total;
				}
			});
		},

		shenhe(item) {
			this.show = true;
			this.form = item;
		},
		viewImage(item, index) {
			console.log('放大查看图片');
			const imgUrl = item; //图片列表，this.imgList是一个图片链接的数组。
			// this.enlargedImage = imgUrl;
			uni.previewImage({
				loop: true,
				urls: imgUrl, //可以展示imgUrl 列表中所有的图片
				current: index //首先当前index对应图片，左右可以切换其他序号的图片
			});
		},
		confirm() {
			console.log(this.form);
			if (!this.form.exJson.discountRate) {
				uni.showModal({
					title: '订单提示',
					content: '请输入折扣优惠',
					success(res) {}
				});
				return;
			} else if (!this.form.exJson.salesmanName) {
				uni.showModal({
					title: '订单提示',
					content: '请输入销售人员姓名',
					success(res) {}
				});
				return;
			} else if (!this.form.exJson.salesmanPhone) {
				uni.showModal({
					title: '订单提示',
					content: '请输入销售人员电话',
					success(res) {}
				});
				return;
			}
			this.form.exJson = JSON.stringify(this.form.exJson);
			updateAudit(this.form);
			let postData = {
				id: this.form.id,
				adminId: uni.getStorageSync('userInfo').id,
				isAudit: 2
			};
			plugsAudit(postData).then((res) => {
				if (res.code == 200) {
					uni.showToast({
						title: '审核成功'
					});
					this.getauditList();
					this.show = false;
				}
			});
			
		},
		cancel() {
			let postData = {
				id: this.form.id,
				adminId: uni.getStorageSync('userInfo').id,
				isAudit: 3
			};
			plugsAudit(postData).then((res) => {
				if (res.code == 200) {
					uni.showToast({
						title: '拒绝成功'
					});
					this.getauditList();
					this.show = false;
				}
			});
			
		}
	}
};
</script>

<style lang="scss">
.content {
	padding: 20rpx;
	background-color: #f5f5f5;
	.box {
		background-color: #fff;
		border-radius: 20rpx;
		margin-bottom: 20rpx;
		padding: 20rpx;
		.box-con {
			display: flex;
			align-items: center;
			padding: 10rpx 0;
			font-size: 28rpx;
			.box-con-left {
				color: #000;
				margin-right: 30rpx;
			}
			.box-con-right {
				color: #1d1e23;
			}
		}
	}
}
.model {
	width: 100%;
	.model-con {
		display: flex;
		align-items: center;
		padding: 10rpx 0;
		font-size: 28rpx;
		.model-con-left {
			margin-right: 10rpx;
		}
		.model-con-right {
			flex: 1;
		}
	}
}
</style>
